import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_pickers/pickers.dart';

class AddManageAddress extends StatefulWidget {
  AddManageAddress({Key key, this.addAddress}) : super(key: key);

  TextEditingController _textNameValue = new TextEditingController(text: '');
  TextEditingController _textPhoneValue = new TextEditingController(text: '');
  TextEditingController _textAddressValue = new TextEditingController(text: '');
  VoidCallback addAddress;

  @override
  _AddManageAddressState createState() => _AddManageAddressState();
}

class _AddManageAddressState extends State<AddManageAddress> {
  String province = '北京市';
  String municipality = '直辖市';
  String district = '东城区';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // child: Text('123'),
      appBar: AppBar(
        centerTitle: true,
        title: Text('添加收货地址'),
        backgroundColor: Colors.blue,
        actions: [
          InkWell(
            onTap: () {
              setState(() {});
            },
            child: InkWell(
              onTap: () {},
              child: Container(
                padding: EdgeInsets.all(18),
                child: Text(
                  '',
                  style: TextStyle(fontSize: 14),
                ),
              ),
            ),
          ),
        ],
      ),
      body: Container(
        color: Colors.black12,
        padding: const EdgeInsets.all(16.0),
        child: ListView(
          children: [
            Container(
                // height: 100,
                padding: EdgeInsets.only(top: 6),
                // color: Colors.red,
                child: Column(children: [
                  Container(
                    margin: EdgeInsets.only(bottom: 10),
                    child: Row(children: [
                      Container(
                          width: 80,
                          // color: Colors.yellow,
                          child: Text('收货人')),
                      Padding(
                        padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
                        child: Container(
                          // color: Colors.black45,
                          width: 150,
                          height: 24,
                          child: TextField(
                            style: TextStyle(
                                fontSize: 16, color: Colors.grey[400]),
                            controller: widget._textNameValue,
                            keyboardType: TextInputType.number,
                            decoration: InputDecoration(
                              border: InputBorder.none,
                              contentPadding: EdgeInsets.all(6.0),
                              hintStyle: new TextStyle(
                                  fontSize: 16, color: Colors.grey[400]),
                              hintText: '请输入姓名',
                            ),
                            // onChanged: _textConsignee,
                            autofocus: false,
                          ),
                        ),
                      ),
                    ]),
                  ),
                  Divider(
                    height: 0,
                    color: Colors.black87,
                    indent: 0,
                    endIndent: 0,
                  ),
                  Container(
                    margin: EdgeInsets.only(bottom: 10, top: 10),
                    child: Row(children: [
                      Container(
                          width: 80,
                          // color: Colors.yellow,
                          child: Text('手机号')),
                      Padding(
                        padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
                        child: Container(
                          // color: Colors.black45,
                          width: 150,
                          height: 24,
                          child: TextField(
                            style: TextStyle(
                                fontSize: 16, color: Colors.grey[400]),
                            controller: widget._textPhoneValue,
                            keyboardType: TextInputType.number,
                            decoration: InputDecoration(
                              border: InputBorder.none,
                              contentPadding: EdgeInsets.all(6.0),
                              hintStyle: new TextStyle(
                                  fontSize: 16, color: Colors.grey[400]),
                              hintText: '请输入手机号',
                            ),
                            // onChanged: _textConsignee,
                            autofocus: false,
                          ),
                        ),
                      ),
                    ]),
                  ),
                  Divider(
                    height: 0,
                    color: Colors.black87,
                    indent: 0,
                    endIndent: 0,
                  ),
                  Container(
                    margin: EdgeInsets.only(bottom: 10, top: 10),
                    child: Row(children: [
                      Container(
                          width: 80,
                          // color: Colors.yellow,
                          child: Text('选择地址')),
                      Padding(
                        padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
                        child: Container(
                          // color: Colors.black45,
                          width: 150,
                          height: 24,
                          child: InkWell(
                            onTap: () {
                              Pickers.showAddressPicker(
                                context,
                                initProvince: this.province,
                                initCity: this.municipality,
                                initTown: this.district,
                                onConfirm: (p, c, t) {
                                  setState(() {
                                    this.province = p;
                                    this.municipality = c;
                                    this.district = t;
                                  });
                                },
                              );
                            },
                            child: Text(this.province +
                                ' ' +
                                this.municipality +
                                ' ' +
                                this.district),
                          ),
                        ),
                      ),
                    ]),
                  ),
                  Container(
                    margin: EdgeInsets.only(bottom: 10, top: 10),
                    child: Row(children: [
                      Container(
                          width: 80,
                          // color: Colors.yellow,
                          child: Text('详细地址')),
                      Padding(
                        padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
                        child: Container(
                          // color: Colors.black45,
                          width: 230,
                          height: 24,

                          child: TextField(
                            style: TextStyle(
                                fontSize: 16, color: Colors.grey[400]),
                            controller: widget._textAddressValue,
                            keyboardType: TextInputType.number,
                            decoration: InputDecoration(
                              border: InputBorder.none,
                              contentPadding: EdgeInsets.all(6.0),
                              hintStyle: new TextStyle(
                                  fontSize: 16, color: Colors.grey[400]),
                              hintText: '请输入详细地址',
                            ),
                            // onChanged: _textConsignee,
                            autofocus: false,
                          ),
                        ),
                      ),
                    ]),
                  ),
                  Divider(
                    height: 0,
                    color: Colors.black87,
                    indent: 0,
                    endIndent: 0,
                  ),
                  InkWell(
                    onTap: () async {
                      var response = await Http.get(
                          'http://xiangrikui.vaiwan.com/userAddress/add?name=${widget._textNameValue.text}&phone=${widget._textPhoneValue.text}&province=${this.province}&municipality=${this.municipality}&district=${this.district}&addressIntro=${widget._textAddressValue.text}');
                      widget.addAddress();
                      setState(() {
                        Navigator.pop(context);
                        
                      });
                    },
                    child: Container(
                        margin: EdgeInsets.only(top: 30),
                        width: 280,
                        height: 34,
                        // color: Colors.red,
                        decoration: new BoxDecoration(
                            color: Colors.red,
                            borderRadius: new BorderRadius.circular((10.0)),
                            boxShadow: [
                              BoxShadow(
                                  color: Colors.black12,
                                  offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                                  blurRadius: 5.0, //阴影模糊程度
                                  spreadRadius: 0.1 //阴影扩散程度
                                  )
                            ]),
                        child: Center(
                            child: Text(
                          '添加',
                          style: TextStyle(color: Colors.white),
                        ))),
                  )
                ])),
          ],
        ),
      ),
    );
  }
}
